<template>
  <!--患者信息 Header -->
  <a-card class="patient-info-header" :body-style="{ padding: '8px 12px' }">
    <div class="flex justify-between items-center">
      <slot name="prefix"></slot>
      <div class="flex items-center flex-1 overflow-hidden">
        <div>
          <a-badge
            v-if="showBadge"
            :count="patientInfo?.czfz === '复诊' ? '复' : '初'"
            class="mr-4 header-badag"
            :offset="[0, 38]"
            :number-style="{ backgroundColor: patientInfo?.czfz === '复诊' ? '#fb923c' : '' }"
          >
            <a-avatar :size="48" :src="avatarMan" />
          </a-badge>
          <a-badge
            v-if="showInsurance && patientInfo?.isOwnExpense !== undefined"
            :count="patientInfo?.isOwnExpense ? '医' : '自'"
            :offset="[-25, -20]"
            :number-style="{ backgroundColor: patientInfo?.isOwnExpense ? '#43e219' : '#fb923c' }"
          />
        </div>

        <div class="flex">
          <div class="ml-2 flex flex-col justify-around">
            <div class="text-xl font-semibold max-w-28 min-w-20 truncate text-primary">
              <PatientPopoverCard v-if="patientInfo.brName" :patient-info="patientInfo" @change="onChange">
                {{ patientInfo?.brName || '姓名' }}
              </PatientPopoverCard>
              <span v-else>姓名</span>
            </div>
            <div class="w-20">
              <span class="mr-4">{{ patientInfo?.brXb || '性别' }}</span>
              <span class="">{{ patientInfo?.brAge ? patientInfo?.brAge : '年龄' }}</span>
            </div>
          </div>
        </div>
        <slot></slot>
      </div>
      <slot name="suffix"></slot>
    </div>
  </a-card>
</template>
<script setup>
import avatarMan from '@/assets/images/avatar-man.png'
import PatientPopoverCard from '@/components/business/PatientPopoverCard'

const emit = defineEmits(['change'])
defineProps({
  patientInfo: {
    type: Object,
    description: '病人信息',
    default: () => ({})
  },
  showBadge: {
    type: Boolean,
    default: true
  },
  showInsurance: {
    type: Boolean,
    default: false
  }
})
const onChange = () => {
  emit('change')
}
</script>
<style lang="less" scoped>
.patient-info-header {
  background-color: var(--secondary-color);
  :deep(.ant-badge-count) {
    background-color: var(--primary-color);
    // top: auto;
    // right: 6px;
    // bottom: 0;
    // box-shadow: none;
  }
  :deep(.ant-badge-not-a-wrapper) {
    width: 0;
  }
}
</style>
